package com.cxl.springbootMybatisWeb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cxl.springbootMybatisWeb.model.Customer;
import com.cxl.springbootMybatisWeb.service.CustomerService;
import com.github.pagehelper.PageHelper;

/**
 * Function: TODO ADD FUNCTION. <br/>
 * Date: 2018年4月23日 上午12:23:42 <br/>
 *
 * @author XilinCheng
 * @version 1.0
 * @Copyright (c) 2018, CXL  All Rights Reserved.
 */
@Controller
@RequestMapping(value = "/customer")
public class CustoemrController {

	@Autowired
	private CustomerService customerService;
	
	
	@ResponseBody
    @PostMapping("/add")
    public int addCustomer(Customer customer){
        return customerService.createCustomer(customer);
    }
	
    @ResponseBody
    @GetMapping("/all")
    public Object findAllCustomer(
            @RequestParam(name = "pageNum", required = false, defaultValue = "1")
                    int pageNum,
            @RequestParam(name = "pageSize", required = false, defaultValue = "10")
                    int pageSize){
        //开始分页
        PageHelper.startPage(pageNum,pageSize);
        return customerService.findBySearch(pageNum, pageSize);
    }
}

